<?php
include("../include/upload.php");
if($mode == "edit") {
	$arr		 = $db->database("epname,epurl,epsub,server,epdemo","ep","epid = '$ipid'");
	$epname 	 = $arr[0][0];
	$epurl 		 = $arr[0][1];
	$epsub 		 = $arr[0][2];
	$server		 = $arr[0][3];
	$epdemo		 = $arr[0][4];
	if($_POST['submit'])	{
		$epname 	 = stripslashes(trim(urldecode($_POST['epname'])));
		$epurl 	 	 = stripslashes(trim(urldecode($_POST['epurl'])));
		$epdemo 	 = stripslashes(trim(urldecode($_POST['epdemo'])));
		$server 	 = stripslashes(trim(urldecode($_POST['server'])));
		$uploadsub	 = ipupload("epsub","subtitle",$ipid);
		if($uploadsub) {
			delFile($arr[0][2]);
			$epsub = $uploadsub;
		}
		else {
			$epsub 		 = stripslashes(trim(urldecode($_POST['epsub_name'])));	
		}
		if($epname && $epurl) {
			$db->dbupdate("ep","	epname 	= '$epname',
						  			epurl 	= '$epurl',
									epsub 	= '$epsub',
									server 	= '$server',
									epdemo 	= '$epdemo'","epid = '$ipid'");
			header("Location: index.php?ipos=epfilm&mode=edit&ipid=".$ipid);
		}
	}
	include_once("./code/php/html_epfilm.php");
}
// delete
elseif($mode == "delete") {
	if($ipid) {
		$arr = $db->database("epsub","ep","epid = '$ipid'");
		delFile($arr[0][0]);
		$db->dbdelete("ep","epid = '$ipid'");
		header("Location: index.php?ipos=film");
	}
}
elseif($mode == "deleteall") {
	$server		=	$_GET['server'];
	if($ipid && $server) {
		$arr = $db->database("epsub","ep","phimid = '$ipid' AND server = '$server'");
		for($i=0;$i<count($arr);$i++) {
			delFile($arr[$i][0]);
		}
		$db->dbdelete("ep","phimid = '$ipid' AND server = '$server'");
		header("Location: index.php?ipos=film");
	}
}
elseif($mode == "error") {
	if($ipid) {
		$ref	=	$_GET['ref'];
		$db->dbupdate("ep","error = 0","epid = '$ipid'");
		header("Location: index.php?ipos=epfilm&ipid=".$ref);
	}
}
else {
	include_once("./code/php/html_epfilm_list.php");
}
?>